package com.example.websocketdemo.service.SHISHI;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.websocketdemo.config.WebSocketTest;

import java.io.IOException;
import java.util.List;

public class SHISHIMonitoringAlarmService {

    public void m(List<List<String>> lists) throws IOException {
        JSONObject zong = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        JSONObject json = new JSONObject();
        JSONObject jsonObject = new JSONObject();
        zong.put("instruction","updatepoi");
        json.put("updatetype","reset");
        json.put("poigroup","baojing");
        json.put("poitype","baojing");
        for (int i = 0; i < lists.size(); i++) {
            List<String> list = lists.get(i);
            if (list.get(0).contains("SCADA_A_")) {
                jsonObject.put("位号",list.get(0).substring(22,26));
                jsonObject.put("读值", String.format("%.2f", list.get(1)));
                jsonObject.put("报警时间", list.get(2));
                jsonObject.put("报警级别", alarmPriority(list.get(4)));
                jsonObject.put("计量单位", "mm");
                jsonObject.put("报警结束时间", "-");
                jsonArray.add(jsonObject);
            }else if (list.get(0).contains("GDS_A_AT")){
                jsonObject.put("位号",list.get(0));
                jsonObject.put("读值", list.get(1));
                jsonObject.put("报警时间", list.get(2));
                jsonObject.put("报警级别", alarmPriority(list.get(4)));
                jsonObject.put("计量单位", "mm");
                jsonObject.put("报警结束时间", "-");
                jsonObject.put("计量单位", "℃");
                jsonArray.add(jsonObject);
            }
        }
        json.put("Array",jsonArray);
        zong.put("param",json);
        WebSocketTest.sendInfo(zong.toJSONString(), "connect");
    }

    private String alarmPriority(String number){
        String value = "";
        if (number.equals("1")){
            value = "高高报";
        } else if (number.equals("2")){
            value = "高报";
        } else if (number.equals("3")){
            value = "低报";
        }
        return  value;
    }
}
